package com.cmpe451.nutty.service;

import java.util.List;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.cmpe451.nutty.dao.RecipeDao;
import com.cmpe451.nutty.dao.TwitterDao;
import com.cmpe451.nutty.model.Comment;
import com.cmpe451.nutty.model.Favorite;
import com.cmpe451.nutty.model.Ingredients;
import com.cmpe451.nutty.model.Menu;
import com.cmpe451.nutty.model.Menu_Recipe;
import com.cmpe451.nutty.model.Rate;
import com.cmpe451.nutty.model.Recipe;
import com.cmpe451.nutty.model.Recipe_Derive;
import com.cmpe451.nutty.model.Recipe_Tag;
import com.cmpe451.nutty.model.Style;
import com.cmpe451.nutty.model.Tools;
import com.cmpe451.nutty.model.Unit;
import com.cmpe451.nutty.model.User;
import com.cmpe451.nutty.so.GuiUser;

@Component
public class RecipeServiceImpl implements RecipeService, InitializingBean {

	
	@Autowired
	private RecipeDao recipeDao;
	
    public Ingredients getIngredientById(long id){
		return recipeDao.findIngredientById(id);
    }
    
	@Override
	public Tools getToolByName(String name) {
		// TODO Auto-generated method stub
		return recipeDao.findToolByName(name);
	}

	@Override
	public Tools getToolById(Long id) {
		// TODO Auto-generated method stub
		return recipeDao.findToolById(id);
	}
    
    public Recipe getRecipeById(Long id){
		return recipeDao.findRecipeById(id);
    }
    
    public void saveIngredient(Ingredients ingredient)
    { 	
    	recipeDao.save(ingredient);   	
    }
	public Ingredients getIngredientByName(String name) {
		return recipeDao.findIngredientByName(name);
	}

    public User getUserById(long id){
		return null;
    }
    
    public List<Recipe> getRecipes(GuiUser user){
    	return recipeDao.findRecipeByUser(user); 	
    }
    
    public List<Ingredients> getIngredients(){
    	return recipeDao.findAll(Ingredients.class);
    }
    
    public List<Recipe> getLatestRecipes(){
    	return recipeDao.findLatestRecipes();
    }

	@Override
	public void afterPropertiesSet() throws Exception {
		// TODO Auto-generated method stub
	}

	@Override
	public void saveRecipe(Recipe recipe) {
		// TODO Auto-generated method stub
		recipeDao.save(recipe);
	}

	@Override
	public void updateRecipe(Recipe recipe) {
		// TODO Auto-generated method stub
		recipeDao.update(recipe);
		
	}
	
	public void updateIngredient(Ingredients ingredient)
	{
		
		recipeDao.update(ingredient);
		
	}

	@Override
	public List<Comment> getCommentsById(Long recipeId) {
		// TODO Auto-generated method stub
		
		return recipeDao.getLatestCommentsById(recipeId);
	}

	@Override
	public void saveComment(Comment newComment) {
		// TODO Auto-generated method stub
		recipeDao.save(newComment);
	}
	
	@Override
	public void saveFav(Favorite newFavorite) {
		// TODO Auto-generated method stub
		recipeDao.save(newFavorite);
	}

	@Override
	public List<Recipe> findSearchResults(String query) {
		
		return recipeDao.findRecipeByQuery(query);
	}

	@Override
	public List<Unit> getUnits() {
		
		return recipeDao.findUnits();
	}

	@Override
	public List<Recipe> getLatestRecipesByUsername(String username) {
		// TODO Auto-generated method stub
		return recipeDao.findLatestRecipesByUsername(username);
	}

	@Override
	public List<Style> getStyles() {
		return recipeDao.findStyles();
	}

	@Override
	public List<Recipe> getLatestRecipesInCircle(List<String> follows) {
		// TODO Auto-generated method stub
		return recipeDao.findLatestRecipesInCircle(follows);
	}

	@Override
	public List<Tools> getTools() {
		// TODO Auto-generated method stub
		return recipeDao.findTools();
	}

	@Override
	public void saveRate(Rate newRate) {
		// TODO Auto-generated method stub
		recipeDao.save(newRate);
	}

	@Override
	public Rate findRatebyRecipe(String username, Long recipeId) {
		// TODO Auto-generated method stub
		return recipeDao.getRatebyRecipe(username, recipeId);
	}

	@Override
	public List<Recipe> rateRecipes(List<Recipe> recipes) {
		// TODO Auto-generated method stub
		return recipeDao.rateLatestRecipes(recipes);
	}

	@Override
	public List<Rate> getTotalRate(Recipe recipe) {
		// TODO Auto-generated method stub
		return recipeDao.getTotalRate(recipe);
	}

	@Override
	public void updateRate(Rate oldRate) {
		// TODO Auto-generated method stub
		recipeDao.update(oldRate);
	}

	@Override
	public void addTag(Recipe_Tag rt) {
		// TODO Auto-generated method stub
		recipeDao.save(rt);
	}

	@Override
	public List<Recipe> findLikedRecipes(String str,int cooktime, String easiness) {
		// TODO Auto-generated method stub
		return recipeDao.getLikedRecipes(str, cooktime, easiness);
	}

	@Override
	public List<Recipe> findDislikedRecipes(String str, int cooktime, String easiness) {
		// TODO Auto-generated method stub
		return recipeDao.getDislikedRecipes(str, cooktime, easiness);
	}

	@Override
	public List<Recipe> findRecipesBasedOnKeywords(String str) {
		// TODO Auto-generated method stub
		return recipeDao.getRecipeBasedOnKeywords(str);
	}
	public List<Recipe> findAllRecipes() {
		// TODO Auto-generated method stub
		return recipeDao.findAll(Recipe.class);
	}

	@Override
	public List<Recipe> findLikedRecipes(String str) {
		// TODO Auto-generated method stub
		return recipeDao.getLikedRecipes(str);
	}

	@Override
	public List<Recipe> findDislikedRecipes(String str) {
		// TODO Auto-generated method stub
		return recipeDao.getDislikedRecipes(str);
	}

	public Favorite getFav(Long userId, Long recipeId) {
		// TODO Auto-generated method stub
		return recipeDao.findFav(userId, recipeId);
	}

	@Override
	public List<Favorite> findFavoritesByUserId(Long userId) {
		// TODO Auto-generated method stub
		return recipeDao.findFavorite(userId);
	}
	
	@Override
	public void deleteFav(Favorite thisFav) {
		// TODO Auto-generated method stub
		recipeDao.delete(thisFav);
	}

	@Override
	public void saveMenu(Menu m) {
		// TODO Auto-generated method stub
		recipeDao.save(m);
		
	}

	@Override
	public void saveMenu_Recipe(Menu_Recipe menuRec) {
		// TODO Auto-generated method stub
		recipeDao.save(menuRec);
		
	}

	@Override
	public List<Menu> getMenusOfUser(long userid) {
		// TODO Auto-generated method stub
		return recipeDao.findMenusOfTheUser(userid);
	}

	@Override
	public List<Menu_Recipe> getMenuRecipePairs(Long id) {
		// TODO Auto-generated method stub
		return recipeDao.findMenuRecipePairs(id);
	}

	@Override
	public List<Recipe> findRecipesWithName(String name) {
		// TODO Auto-generated method stub
		return recipeDao.findRecipeByName(name);
	}

	@Override
	public void saveDerivedRecipe(Recipe_Derive newRecipe_Derive) {
		
		recipeDao.save(newRecipe_Derive);
		
	}

	@Override
	public List<Recipe_Derive> findDerivedRecipesById(Long recipeId) {
		// TODO Auto-generated method stub
		return recipeDao.getDerivedRecipesById(recipeId);
	}
	
}
